<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class HhmGoodsSpecItem extends Model
{
    use SoftDeletes;

    protected $table = 'ims_hhm_goods_spec_item';
    
    protected $fillable = [
        'uniacid', 'spec_id', 'title', 'thumb', 'color_value',
        'show', 'display_order', 'value_id', 'virtual'
    ];

    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';
    const DELETED_AT = 'deleted_at';

    // 禁用时间戳自动转换为Carbon对象，因为表中使用整型存储
    public $timestamps = true;
    protected $dateFormat = 'U'; // 使用Unix时间戳

    /**
     * 关联规格
     */
    public function spec()
    {
        return $this->belongsTo(HhmGoodsSpec::class, 'spec_id', 'id');
    }

    /**
     * 获取缩略图完整URL
     */
    public function getThumbUrlAttribute()
    {
        if (empty($this->thumb)) {
            return '';
        }
        return \App\Services\ImageUrlService::processImageUrl($this->thumb);
    }
}

